/*     */ package net.gxf.learn.one;
/*     */ 
/*     */ import org.lwjgl.LWJGLException;
/*     */ import org.lwjgl.Sys;
/*     */ import org.lwjgl.input.Keyboard;
/*     */ import org.lwjgl.opengl.Display;
/*     */ import org.lwjgl.opengl.DisplayMode;
/*     */ import org.lwjgl.opengl.GL11;
/*     */ 
/*     */ public class TimerExample
/*     */ {
/*  17 */   float x = 400.0F; float y = 300.0F;
/*     */ 
/*  19 */   float rotation = 0.0F;
/*     */   long lastFrame;
/*     */   int fps;
/*     */   long lastFPS;
/*     */ 
/*     */   public void start()
/*     */   {
/*     */     try
/*     */     {
/*  31 */       Display.setDisplayMode(new DisplayMode(800, 600));
/*     */ 
/*  33 */       Display.create();
/*     */     } catch (LWJGLException e) {
/*  35 */       e.printStackTrace();
/*  36 */       System.exit(0);
/*     */     }
/*     */ 
/*  39 */     initGL();
/*  40 */     getDelta();
/*  41 */     this.lastFPS = getTime();
/*     */ 
/*  43 */     while (!Display.isCloseRequested()) {
/*  44 */       int delta = getDelta();
/*     */ 
/*  46 */       update(delta);
/*  47 */       renderGL();
/*     */ 
/*  49 */       Display.update();
/*  50 */       Display.sync(70);
/*  51 */       this.rotation += 0.5F;
/*     */     }
/*     */ 
/*  54 */     Display.destroy();
/*     */   }
/*     */ 
/*     */   public void update(int delta)
/*     */   {
/*  59 */     this.rotation += 0.15F * delta;
/*     */ 
/*  61 */     if ((Keyboard.isKeyDown(203)) || (Keyboard.isKeyDown(30))) this.x -= 0.35F * delta;
/*  62 */     if ((Keyboard.isKeyDown(205)) || (Keyboard.isKeyDown(32))) this.x += 0.35F * delta;
/*     */ 
/*  64 */     if ((Keyboard.isKeyDown(200)) || (Keyboard.isKeyDown(17))) this.y -= 0.35F * delta;
/*  65 */     if ((Keyboard.isKeyDown(208)) || (Keyboard.isKeyDown(31))) this.y += 0.35F * delta;
/*     */ 
/*  68 */     if (this.x < 0.0F) this.x = 0.0F;
/*  69 */     if (this.x > 800.0F) this.x = 800.0F;
/*  70 */     if (this.y < 0.0F) this.y = 0.0F;
/*  71 */     if (this.y > 600.0F) this.y = 600.0F;
/*     */ 
/*  73 */     updateFPS();
/*     */   }
/*     */ 
/*     */   public int getDelta()
/*     */   {
/*  83 */     long time = getTime();
/*  84 */     int delta = (int)(time - this.lastFrame);
/*  85 */     this.lastFrame = time;
/*     */ 
/*  87 */     return delta;
/*     */   }
/*     */ 
/*     */   public long getTime()
/*     */   {
/*  96 */     return Sys.getTime() * 1000L / Sys.getTimerResolution();
/*     */   }
/*     */ 
/*     */   public void updateFPS()
/*     */   {
/* 103 */     if (getTime() - this.lastFPS > 1000L) {
/* 104 */       Display.setTitle("FPS: " + this.fps);
/* 105 */       this.fps = 0;
/* 106 */       this.lastFPS += 1000L;
/*     */     }
/* 108 */     this.fps += 1;
/*     */   }
/*     */ 
/*     */   public void initGL() {
/* 112 */     GL11.glMatrixMode(5889);
/* 113 */     GL11.glLoadIdentity();
/* 114 */     GL11.glOrtho(0.0D, 800.0D, 600.0D, 0.0D, 1.0D, -1.0D);
/* 115 */     GL11.glMatrixMode(5888);
/*     */   }
/*     */ 
/*     */   public void renderGL()
/*     */   {
/* 120 */     GL11.glClear(16640);
/*     */ 
/* 123 */     GL11.glColor3f(0.5F, 0.5F, 1.0F);
/*     */ 
/* 126 */     GL11.glPushMatrix();
/* 127 */     GL11.glBegin(7);
/* 128 */     GL11.glVertex2f(this.x - 50.0F, this.y - 50.0F);
/* 129 */     GL11.glVertex2f(this.x + 50.0F, this.y - 50.0F);
/* 130 */     GL11.glVertex2f(this.x + 50.0F, this.y + 50.0F);
/* 131 */     GL11.glVertex2f(this.x - 50.0F, this.y + 50.0F);
/* 132 */     GL11.glEnd();
/* 133 */     GL11.glTranslatef(this.x, this.y, 0.0F);
/* 134 */     GL11.glRotatef(this.rotation, 0.0F, 0.0F, 1.0F);
/* 135 */     GL11.glTranslatef(-this.x, -this.y, 0.0F);
/*     */ 
/* 137 */     GL11.glBegin(7);
/* 138 */     GL11.glVertex2f(this.x - 50.0F, this.y - 50.0F);
/* 139 */     GL11.glVertex2f(this.x + 50.0F, this.y - 50.0F);
/* 140 */     GL11.glVertex2f(this.x + 50.0F, this.y + 50.0F);
/* 141 */     GL11.glVertex2f(this.x - 50.0F, this.y + 50.0F);
/* 142 */     GL11.glEnd();
/*     */   }
/*     */ 
/*     */   public static void main(String[] argv)
/*     */   {
/* 147 */     TimerExample timerExample = new TimerExample();
/* 148 */     timerExample.start();
/*     */   }
/*     */ }

/* Location:           C:\DBDownload\lwjglDemo2\lwjglDemo2\Run.jar
 * Qualified Name:     com.learn.one.TimerExample
 * JD-Core Version:    0.6.2
 */